package com.rightsidetech.system.service.impl;

import com.rightsidetech.commom.base.ResponseData;
import com.rightsidetech.system.dtos.response.SysDicDIcInfoResp;
import com.rightsidetech.system.dtos.response.SysDicDIcNameResp;
import com.rightsidetech.system.entity.SysDic;
import com.rightsidetech.system.mapper.SysDicMapper;
import com.rightsidetech.system.service.SysDicService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author: yhr
 * @Date: 2022-02-09 09:17
 */
@Service("sysDicServiceImpl")
public class SysDicServiceImpl implements SysDicService {
    @Resource
    private SysDicMapper sysDicMapper;

    @Override
    public ResponseData<List<SysDicDIcNameResp>> parentRule() {
        return ResponseData.success(sysDicMapper.selectByParentRule());
    }

    @Override
    public ResponseData<List<SysDicDIcNameResp>> parentRuleList(String dicType) {
        return ResponseData.success(sysDicMapper.parentRuleInfo(dicType));
    }

    @Override
    public SysDic selectRuleByCode(String dicCode) {
        return sysDicMapper.selectRuleByCode(dicCode);
    }

    @Override
    public ResponseData<List<SysDicDIcInfoResp>> parentRuleInfo(Long dicId) {
        List<SysDicDIcInfoResp> resps = sysDicMapper.selectRuleInfo(dicId);
        for (SysDicDIcInfoResp resp:resps) {
            if (resp.getCount() > 0){
                resp.setDIcInfo(sysDicMapper.selectRuleInfo(resp.getDicId()));
            }
        }
        return ResponseData.success(resps);
    }

    @Override
    public ResponseData<List<SysDicDIcInfoResp>> jFParentRuleInfo(Long dicId) {
        List<SysDicDIcInfoResp> resps = null;
        if(dicId == 2){
            resps = sysDicMapper.selectJFRuleInfo(15L);
        }
        if(dicId == 1){
            resps = sysDicMapper.selectRuleInfo(15L);
        }

        return ResponseData.success(resps);
    }

}
